// EmulateLCDSegmentsView.cpp : implementation of the CEmulateLCDSegmentsView class
//

#include "stdafx.h"
#include "EmulateLCDSegments.h"

#include "EmulateLCDSegmentsDoc.h"
#include "EmulateLCDSegmentsView.h"
#include ".\emulatelcdsegmentsview.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


	const float Points[4*8*sizeof(short int)]=
	{
		0,0,1,0,//0
		0,0,0,0,//1
		0,0,0,0,//2
		1,0,0.5,1,//3
        1,0,1,1,//4
		0,0,0.5,1,//5
		0,0,0,1,//6
		0.5,0,0.5,1,//7
		1,1,1,2,//8
		0,1,0.5,1,//9
		0,1,0,2,//10
		0.5,1,1,1,//11
		0,2,1,2,//12
		0.5,1,0.5,2,//13
		0.5,1,0,2,//14
		0.5,1,1,2//15
	};
// CEmulateLCDSegmentsView

IMPLEMENT_DYNCREATE(CEmulateLCDSegmentsView, CScrollView)

BEGIN_MESSAGE_MAP(CEmulateLCDSegmentsView, CScrollView)
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
	ON_COMMAND(ID_SEGMENTS_INPUT, OnSegmentsInput)
END_MESSAGE_MAP()

// CEmulateLCDSegmentsView construction/destruction

CEmulateLCDSegmentsView::CEmulateLCDSegmentsView()
: SegSZ(200)
{
	// TODO: add construction code here
    LeftUp[0]=100;
	LeftUp[1]=100;
}

CEmulateLCDSegmentsView::~CEmulateLCDSegmentsView()
{
}

BOOL CEmulateLCDSegmentsView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CScrollView::PreCreateWindow(cs);
}

// CEmulateLCDSegmentsView drawing

void CEmulateLCDSegmentsView::OnDraw(CDC* pDC)
{
	CEmulateLCDSegmentsDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	// TODO: add draw code for native data here
	for (size_t LoopIndex=0;LoopIndex<8*sizeof(short int);LoopIndex++)
	{
        if ((pDoc->CodeDisplaySimbol)&(1<<LoopIndex))
		{
			pDC->MoveTo(LeftUp[0]+(int)((float)SegSZ*Points[4*LoopIndex]),LeftUp[1]+(int)((float)SegSZ*Points[4*LoopIndex+1]));
			pDC->LineTo(LeftUp[0]+(int)((float)SegSZ*Points[4*LoopIndex+2]),LeftUp[1]+(int)((float)SegSZ*Points[4*LoopIndex+3]));
		}
	}
}

void CEmulateLCDSegmentsView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();
	CSize sizeTotal;
	// TODO: calculate the total size of this view
	//sizeTotal.cx = sizeTotal.cy = 100;	
	sizeTotal.cx = 2*LeftUp[0]+SegSZ;
	sizeTotal.cy = 2*LeftUp[1]+2*SegSZ;
	SetScrollSizes(MM_TEXT, sizeTotal);
}


// CEmulateLCDSegmentsView printing

BOOL CEmulateLCDSegmentsView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CEmulateLCDSegmentsView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CEmulateLCDSegmentsView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}


// CEmulateLCDSegmentsView diagnostics

#ifdef _DEBUG
void CEmulateLCDSegmentsView::AssertValid() const
{
	CScrollView::AssertValid();
}

void CEmulateLCDSegmentsView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

CEmulateLCDSegmentsDoc* CEmulateLCDSegmentsView::GetDocument() const // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEmulateLCDSegmentsDoc)));
	return (CEmulateLCDSegmentsDoc*)m_pDocument;
}
#endif //_DEBUG


// CEmulateLCDSegmentsView message handlers

void CEmulateLCDSegmentsView::OnSegmentsInput()
{
	// TODO: Add your command handler code here
	CEmulateLCDSegmentsDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;
	pDoc->OnSegmentsInput();
	Invalidate();
}
